/*
 * Copyright 2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gitee.joyz.api.result.i18n;

import io.gitee.joyz.api.result.i18n.exception.NoSuchMessageException;

import java.util.Locale;

/**
 * 国际化消息接口
 *
 * @author JoyZ
 */
public interface LocaleMessage {

    /**
     * 尝试通过 code 参数解析消息
     *
     * @param code           消息代码
     * @param arguments      消息参数
     * @param defaultMessage 默认消息
     * @param locale         语言环境
     * @return 如果查找成功, 则返回解析后的消息, 反之则将 defaultMessage 作为消息进行解析 (有可能为 null)
     */
    String getMessage(String code, Object[] arguments, String defaultMessage, Locale locale);


    /**
     * 尝试通过 code 参数解析消息
     *
     * @param code      消息代码
     * @param arguments 消息参数
     * @param locale    语言环境
     * @return 如果查找成功, 则返回解析后的消息, 反之则抛出异常
     * @throws NoSuchMessageException 当无法根据给定的 code 查找到对应的消息时会抛出该异常
     */
    String getMessage(String code, Object[] arguments, Locale locale) throws NoSuchMessageException;
}
